*November 16, 2025
**Wilk, Deza, Hodge, Danagoulian (2025) Couch-Locked with the Munchies: Effects of Recreational Marijuana Laws on Exercise and Nutrition

set segmentsize 2.5g
set more off
cap log close
eststo clear

local cat 		`" "2" "3" "4" "5" "'
local cat_word		`" "Fast_Food" "Conv_Store" "Grocery" "Dollar" "'
* NOTE: categories; 2 == fast food, 3 == convenience store, 4 == grocery store, 5 == dollar store
local cat_label 	`" "% Change in Fast Food Visits" "% Change in Convenience Store Visits" "% Change in Grocery Store Visits" "% Change in Dollar Store Visits" "'
local num_cats: 	word count `cat'

forvalues i = 1/`num_cats' {

local results_list
local x: 		word `i' of `cat' 
local title: 		word `i' of `cat_label' 
local catw:		word `i' of `cat_word'

use "poi_rml.dta", clear

gen lnnvh`x' = ln(nv`x'+1)
sum lnnvh`x', detail
keep if lnnvh`x' <= r(p99)

***** (1) BJS Models *****
* (a) BJS Regression
	* (a.1) BASE model
eststo base_`catw': did_imputation lnnvh`x' fips_n wy Ei [aw=number_devices_residing] if period>=-78 & period<=78, fe(fips_n wy start) cluster(st) autosample maxit(500)
	estadd ysumm
	* (a.2) BASE model w/ st-mo FEs
eststo base_`catw'_stmo: did_imputation lnnvh`x' fips_n wy Ei [aw=number_devices_residing] if period>=-78 & period<=78, fe(fips_n wy start st#month) cluster(st) autosample maxit(500) tol(0.001)
	estadd ysumm
	* (a.3) Controls
eststo sp1_`catw': did_imputation lnnvh`x' fips_n wy Ei [aw=number_devices_residing] if period>=-78 & period<=78, fe(fips_n wy start shelter) controls(age2024 edu_hs marry) cluster(st) autosample maxit(500) tol(0.001)
	estadd ysumm
	* (a.4) Controls w/ st-mo FEs
eststo sp2_`catw': did_imputation lnnvh`x' fips_n wy Ei [aw=number_devices_residing] if period>=-78 & period<=78, fe(fips_n wy start shelter st#mo) controls(age2024 edu_hs marry) cluster(st) autosample maxit(500) tol(0.001)
	estadd ysumm
	
	** Time Detrended Models **	
	* (b.1-1) Time-detrend w/ state-month FEs & controls
qui reg lnnvh`x' i.g_id##c.wy i.start i.shelter age2024 edu_hs marry i.wy i.fips_n i.st#i.month [aw=number_devices_residing] if post_start==0 & treat==1 & period>=-78, cluster(st)
	predict lnnvh`x'_res1, residual
	* (b.1-2) Detrended w/ st-mo & controls
eststo sp2_`catw'_res: did_imputation lnnvh`x'_res1 fips_n wy Ei if period>=-78 & period<=78, fe(fips_n wy st#month) cluster(st) autosample maxit(500) tol(0.001)
	estadd ysumm
	* (b.2-1) Time-detrend BASE model
qui reg lnnvh`x' i.g_id##c.wy i.start i.wy i.fips_n [aw=number_devices_residing] if post_start==0 & treat==1 & period>=-78, cluster(st)
	predict lnnvh`x'_res2, residual
	* (b.2-2) Detrended BJS Regression
eststo base_`catw'_res: did_imputation lnnvh`x'_res2 fips_n wy Ei if period>=-78 & period<=78, fe(fips_n wy) cluster(st) autosample maxit(500)
	estadd ysumm
	* (b.3-1) Time-detrend w/ controls
qui reg lnnvh`x' i.g_id##c.wy i.start i.shelter age2024 edu_hs marry i.wy i.fips_n [aw=number_devices_residing] if post_start==0 & treat==1 & period>=-78, cluster(st)
	predict lnnvh`x'_res3, residual
	* (b.3-2) Detrended w/ controls
eststo sp1_`catw'_res: did_imputation lnnvh`x'_res3 fips_n wy Ei if period>=-78 & period<=78, fe(fips_n wy) cluster(st) autosample maxit(500) tol(0.001)
	estadd ysumm
	
***** EVENT STUDIES *****
replace qy = qy + 1 if date==td(30sep2019) | date==td(30dec2019) | date==td(30mar2020) | date==td(29jun2020) | date==td(28sep2020) | date==td(28dec2020) | date==td(29mar2021) | date==td(28jun2021)
drop periodqy prdqy

levelsof st if g_id==0, local(s) 
gen nontreatqy = .
set seed 1234
sort st
foreach z of local s {
	replace nontreatqy = runiformint(6,10) if st==`z'
	by st: replace nontreatqy = nontreatqy[1]
} // state loop

gen periodqy = 0
replace periodqy = qy - gqy if gqy > 0
replace periodqy = qy - nontreatqy if gqy == 0 & nontreatqy!=.
gen prdqy = periodqy + 7
drop if prdqy < 0 | prdqy > 12

	* (b.1) Detrend
		* OLD
qui reg lnnvh`x' i.gqy#i.prdqy i.shelter i.start age2024 edu_hs marry i.qy i.fips_n [aw=number_devices_residing] if post_start==0 & treat==1, cluster(st)
	predict lnnvh`x'_res4, residual
		* NEW
qui reghdfe lnnvh`x' i.gqy##c.qy i.start i.shelter age2024 edu_hs marry [aw=number_devices_residing] if post_start==0 & treat==1, absorb(fe1=fips_n fe2=qy) residuals(lnnvh`x'_res5) cluster(st)
	bys fips_n (fe1): replace fe1 = fe1[1]
	replace fe1 = 0 if fe1 == .
	bys qy (fe2): replace fe2 = fe2[1]
	replace fe2 = 0 if fe2 == .
	gen d = fe1 + fe2
	predict xb, xb
	gen lnnvh`x'_fit = xb + d
	replace lnnvh`x'_res5 = lnnvh`x' - lnnvh`x'_fit
	drop fe1-lnnvh`x'_fit
		* NEW st-mo FE
qui reghdfe lnnvh`x' i.gqy##c.qy i.start i.shelter age2024 edu_hs marry i.st#i.month [aw=number_devices_residing] if post_start==0 & treat==1, absorb(fe1=fips_n fe2=qy) residuals(lnnvh`x'_res6) cluster(st)
	bys fips_n (fe1): replace fe1 = fe1[1]
	replace fe1 = 0 if fe1 == .
	bys qy (fe2): replace fe2 = fe2[1]
	replace fe2 = 0 if fe2 == .
	gen d = fe1 + fe2
	predict xb, xb
	gen lnnvh`x'_fit = xb + d
	replace lnnvh`x'_res6 = lnnvh`x' - lnnvh`x'_fit
	drop fe1-lnnvh`x'_fit
	
	* (b.2) TWFE to capture detrended coefficients
		* Old
reghdfe lnnvh`x'_res4 b6i.prdqy##i.post_start, absorb(fips_n) cluster(st) baselevel
		* New
reghdfe lnnvh`x'_res5 b6i.prdqy##i.post_start, absorb(fips_n) cluster(st) baselevel
		* New w/ st-mo FE
reghdfe lnnvh`x'_res6 b6i.prdqy##i.post_start, absorb(fips_n) cluster(st) baselevel
		* Not-Detrended
reghdfe lnnvh`x' b6i.prdqy##i.post_start i.start i.shelter age2024 edu_hs marry [aw=number_devices_residing], absorb(fips_n) cluster(st) baselevel
		* Not-Detrended w/ st-mo FE
reghdfe lnnvh`x' b6i.prdqy##i.post_start i.start i.shelter age2024 edu_hs marry i.st#i.month [aw=number_devices_residing], absorb(fips_n) cluster(st) baselevel

local results_list base_`catw' base_`catw'_stmo sp1_`catw' sp2_`catw' base_`catw'_res sp2_`catw'_res base_`catw'_res
estout `results_list' using "results/rr_adv_output_main_`catw'_6.xls", cells(b(star label(Coef.) fmt(3)) se(par(`"="("'`")""') label(Std. Err.) fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.005) stats(ymean ysd r2 N, fmt(3 3 3 0)) legend label append
eststo clear
} // category loop

***** End-of-File *****
